package menu

var sqlGetAllMenus = `
SELECT id, label, path, icon, expand,pid
FROM meta_menu_#tenant_id
WHERE status = 1
ORDER BY pid asc, sort_order asc, id asc;
`
var sqlInsertMenu = []string{
	`SELECT COALESCE((SELECT MAX(sort_order) FROM meta_menu_#tenant_id WHERE pid = @pid), 0) AS max_sort_order`,
	`INSERT INTO meta_menu_#tenant_id (label, path, icon, expand, pid,sort_order, status)
VALUES (@label, @path, @icon, @expand, @pid,@max_sort_order + 1,1)`}

var sqlDeleteMenu = `
DELETE FROM meta_menu_#tenant_id WHERE id = @id;
`
var sqlUpdateStatus = `
UPDATE meta_menu_#tenant_id SET status = @status WHERE id = @id;
`
var sqlUpdateMenu = `
UPDATE meta_menu_#tenant_id
SET label = @label, path = @path, icon = @icon, expand = @expand
WHERE id = @id;
`
var sqlMoveMenuBackward = []string{
	`SELECT sort_order,id as pid from meta_menu_#tenant_id WHERE id = @targetId`,
	`UPDATE meta_menu_#tenant_id SET sort_order = sort_order + 2 WHERE pid = @pid AND sort_order >= @sort_order AND id != @targetId`,
	`UPDATE meta_menu_#tenant_id SET pid = @pid, sort_order = @sort_order + 1 WHERE id = @sourceId;`,
}

var sqlMoveMenuForward = []string{
	`SELECT sort_order,id as pid from meta_menu_#tenant_id WHERE id = @targetId`,
	`UPDATE meta_menu_#tenant_id SET sort_order = sort_order + 1 WHERE pid = @pid AND sort_order >= @sort_order;`,
	`UPDATE meta_menu_#tenant_id SET pid = @pid, sort_order = @sort_order WHERE id = @sourceId;`}
